
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>头部</title>
		<link rel="stylesheet" type="text/css" href="../../Resours/css/Main.css"/>
		<link rel="stylesheet" type="text/css" href="../../Resours/css/bootstrap.min.css">
	</head>
	<body onload=" fun()">
		<div id="head">
			<div id="head_top">
				<span id="name"></span>
				<a href="../User/User.html" target="_blank"  id="user" class="btn btn-success btn-sm ">用户中心</a>
				<a href="../User/Login.html" target="_blank" id="login" class="btn btn-success btn-sm " >请登录</a>
				<a href="../User/Register.html" target="_blank" class="btn btn-success btn-sm " id="reg">请注册</a>
				<a href="/Shopx/UserServlet?action=eval" target="center" class="btn btn-success btn-sm ">评价 </a>
				<a  target="_blank" id="exit" onclick="exit()" class="btn btn-danger btn-sm ">退出登录</a>
			</div>
			<div id="head_bottom">
				<!-- 商标 -->
				<img id="logo" src="../../Resours/images/Main/logo.png" >
				<div id="nav">
					<button class="btn btn-success" disabled="disabled">商品分类 </button>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=1" target="center" class="btn btn-success btn-sm "> 冲泡类 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=2" target="center" class="btn btn-success btn-sm "> 腊制品 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=3" target="center" class="btn btn-success btn-sm "> 粮油调料 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=4" target="center" class="btn btn-success btn-sm "> 零食 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=5" target="center" class="btn btn-success btn-sm "> 肉类 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=6" target="center" class="btn btn-success btn-sm "> 水产 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=7" target="center" class="btn btn-success btn-sm "> 水果 </a>
					<a href="/Shopx/GoodsServlet?action=showgoods&category=8" target="center" class="btn btn-success btn-sm "> 饮品 </a>
				</div>
			</div>
		</div>
		
		<script src="../../Resours/js/jquery-3.3.1.min.js"></script>
		<script>
        //在页面加载完成后
       
       function fun() {
               //发送ajax请求
               $.get("/Shopx/UserServlet?action=checklogin",function (data) {
	               		//获得id为name的span
	               		var span = $("#name");
	               		
	               		//获得id为exit的a
	               		var exit = 	$("#exit");
	               		//获得id为login的a
	               		var login = 	$("#login");
	               		//获得id为user的a
	               		var user = 	$("#user");
	               		
	               		//获得注册按钮
	               		var reg = $("#reg");
	               		
	                   //判断session里的用户名是否存在
	                   if(data != "0"){
	                	 //如果存在就在span上显示用户名
		                   	span.html("用户名："+data);
		                   	//隐藏登陆标签
		                   //隐藏：
		                   	login.hide();
							//显示退出按钮：
							exit.show();
							//显示用户信息按钮
							user.show();
							//隐藏注册按钮
		                   	reg.hide();
	                   	
                  	 }else{
                	 //如果不存在,移除用户名
	                   	span.html(""); 
	                  //隐藏用户信息按钮
	                  user.hide();
	                   	//	隐藏exit标签：
	                   exit.hide();
	                   	//显示登陆标签：
						login.show();
						//显示注册按钮
	                   	reg.show();
                   	
                   }
               });
        }
        //window.setInterval("fun()",1);
        function exit(){
        	if(confirm('确定要退出吗?')){
        		 $.get("/Shopx/UserServlet?action=exit",function (data) {
        			 fun();
        		 },'json');
			}else{
			}
        }
        
        
    
	</script>
	<script src="../../Resours/js/popper.min.js"></script>
	<script src="../../Resours/js/bootstrap.min.js"></script>
	</body>
</html>

